package com.easy;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by Lxk on 2020/2/14.
 */
public class Solution205 {

    public boolean isIsomorphic(String s, String t) {
        if (s.length() != t.length()) {
            return false;
        }
        if (isMany2One(s, t) && isMany2One(t, s)) {
            return true;
        } else {
            return false;
        }
    }

    boolean isMany2One(String s, String t) {
        Map<Character, Character> chMap = new HashMap<>();
        for (int i = 0; i < s.length(); i++) {
            if (chMap.keySet().contains(s.charAt(i))) {
                Character ch = chMap.get(s.charAt(i));
                if (!ch.equals(t.charAt(i))) {
                    return false;
                }
            } else {
                chMap.put(s.charAt(i), t.charAt(i));
            }
        }
        return true;
    }

    public static void main(String[] args) {
        String str = "eg";
        String str2 = "dd";
        Solution205 solution205 = new Solution205();
        System.out.println(solution205.isIsomorphic(str, str2));
    }

}
